<?php
/**
 * Controller_Notification
 *
 * Класс Controller_Admin_Notification отвечает за оповещения по электронной почте
 *
 * @author Александр Егоров <slamer86@gmail.com>
 * @version 1.0
 */
class Controller_Notification extends Controller_Base {

	public function __construct(&$arrRequest) {
		parent::__construct($arrRequest);
		$this->showRightColumn = false;
	  $this->showLeftColumn = false;
		$this->showRightColumn = false;

    $this->setCrumbs(array(
      array('url' => W_ABSPATH,'name' => 'Home page'),
      array('url' => W_ABSPATH . 'administration/','name' => 'Administration')
    ));
		if (! SimpleAdministration::isAdmin()) {
		  $this->show403Error();
		  exit();
		}
  	if (!isset($arrRequest[2])) $arrRequest[2] = ''; //учитываем "/" на конце
		switch ($arrRequest[2]) {
		  case '':
		    $this->getNotifications();
				break;
			default: $this->show404Error();
		}

	}

	/**
	 * Выводим все заказы для администратора
	 *
	 */
	public function getNotifications() {
		$this->title = 'Notifications';
		$this->addCrumb('Notifications');
		if (isset($_POST['save'])) {
			unset($_POST['save']);
			$objDB = Service_Database::instance();
			foreach ($_POST as $key => $text) {
				$stmt = "UPDATE notification_text SET text = '" . $text . "' WHERE function = '" . $key . "'";
				$objDB->query($stmt);
			}
		}
		$arrNotifications = User_Notification::getAllForAdmin();
		$this->showHeader();
      View_Block::showBorderBlockOpen(true);
		    $this->showCrumbs();
		    $this->showH1($this->title);
		    echo '<div id="leftAdministration">';
		      View_Admin::showAdminMenu();
		    echo '</div>';
		    echo '<div id="mainAdministration">';
      		View_Notification::showNotifications($arrNotifications);
		    echo '</div>';
		    echo '<p class="clearLine"></p><p class="clearRight"></p>';
		  View_Block::showBorderBlockClose();
		$this->showFooter();
	}


}